<% no_filter = params[:filter].blank? %>
<% org_filter = params[:filter].to_s.match?(/^org$/i) %>
<% comments_filter = params[:filter].to_s.match?(/^comments$/i) %>
<% user_comments = comments_filter && params[:org_id].blank? %>
<% user_posts = params[:filter].to_s.match?(/^posts$/i) && params[:org_id].blank? %>

<nav class="hidden m:block pt-4" aria-label="<%= t("views.notifications.nav.aria_label") %>">
  <div>
    <% if @organizations.present? %>
      <h3 class="crayons-subtitle-3 mb-4 pl-2"><%= @user.name %></h3>
    <% end %>

    <a
      class="crayons-link crayons-link--block <%= "crayons-link--current" if no_filter %>"
      href="<%= notifications_path %>">
      <%= t("views.notifications.nav.all") %>
    </a>
    <a
      class="crayons-link crayons-link--block <%= "crayons-link--current" if user_comments %>"
      href="<%= notifications_filter_path(:comments) %>">
      <%= t("views.notifications.nav.comments") %>
    </a>
    <a
      class="crayons-link crayons-link--block <%= "crayons-link--current" if user_posts %>"
      href="<%= notifications_filter_path(:posts) %>">
      <%= t("views.notifications.nav.posts") %>
    </a>
  </div>

  <% if @organizations.present? %>
    <% @organizations.each do |org| %>
      <div class="pt-6">
        <h3 class="crayons-subtitle-3 mb-4 pl-2"><%= org.name %></h3>
        <a
          class="crayons-link crayons-link--block <%= "crayons-link--current" if org_filter && params[:org_id].to_i == org.id %>"
          href="<%= notifications_filter_org_path(filter: :org, org_id: org.id) %>">
          <%= t("views.notifications.nav.all") %>
        </a>
        <a
          class="crayons-link crayons-link--block <%= "crayons-link--current" if comments_filter && params[:org_id].to_i == org.id %>"
          href="<%= notifications_filter_org_path(filter: :comments, org_id: org.id) %>">
          <%= t("views.notifications.nav.comments") %>
        </a>
      </div>
    <% end %>
  <% end %>
</nav>

<nav class="block m:hidden px-3" aria-label="<%= t("views.notifications.nav.aria_label") %>">
  <% if @organizations.present? %>
    <select id="notifications-filter__select" class="crayons-select mb-2">
      <option value="<%= notifications_path %>"><%= @user.name %></option>
      <% @organizations.each do |org| %>
        <option value="<%= notifications_filter_org_path(filter: :org, org_id: org.id) %>" <%= "selected" if params[:org_id].to_i == org.id %>><%= org.name %></option>
      <% end %>
    </select>
  <% end %>

  <div class="crayons-tabs <%= "hidden" if params[:org_id].present? %>">
    <ul class="crayons-tabs__list">
      <li>
        <a
          data-text="All"
          class="crayons-tabs__item <%= "crayons-tabs__item--current" if no_filter %>"
          href="<%= notifications_path %>"
          aria-current="<%= "page" if no_filter %>">
          <%= t("views.notifications.nav.all") %>
        </a>
      </li>
      <li>
        <a
          data-text="Comments"
          class="crayons-tabs__item <%= "crayons-tabs__item--current" if user_comments %>"
          href="<%= notifications_filter_path(:comments) %>"
          aria-current="<%= "page" if user_comments %>">
          <%= t("views.notifications.nav.comments") %>
        </a>
      </li>
      <li>
        <a
          data-text="Posts"
          class="crayons-tabs__item <%= "crayons-tabs__item--current" if user_posts %>"
          href="<%= notifications_filter_path(:posts) %>"
          aria-current="<%= "page" if user_posts %>">
          <%= t("views.notifications.nav.posts") %>
        </a>
      </li>
    </ul>
  </div>

  <% if @organizations.present? %>
    <% @organizations.each do |org| %>
      <div class="crayons-tabs <%= "hidden" unless params[:org_id].to_i == org.id %>">
        <a
          data-text="All"
          class="crayons-tabs__item <%= "crayons-tabs__item--current" if org_filter && params[:org_id].to_i == org.id %>"
          href="<%= notifications_filter_org_path(filter: :org, org_id: org.id) %>">
          <%= t("views.notifications.nav.all") %>
        </a>
        <a
          data-text="Comments"
          class="crayons-tabs__item <%= "crayons-tabs__item--current" if comments_filter && params[:org_id].to_i == org.id %>"
          href="<%= notifications_filter_org_path(filter: :comments, org_id: org.id) %>">
          <%= t("views.notifications.nav.comments") %>
        </a>
      </div>
    <% end %>
  <% end %>
</nav>
